package eecs285.proj4.gui;

//Class: EECS 285
//Project: 
//Due Date: Monday December 6th, 2010

//NOTES: 

import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import static eecs.util.Utility.*;

/**
 * A derived class for actions performed on a Markerboard.
 * 
 * @author Easton Thomas
 * @author Stubbed by Hans Marquard
 */
@SuppressWarnings("serial")
public class Text extends MAction
{

  private static int DEFAULT_FONT_SIZE = 20;
  private static int DEFAULT_FONT_STYLE = Font.PLAIN;

  private Font font = null;
  private int size = DEFAULT_FONT_SIZE;
  private int style = DEFAULT_FONT_STYLE;
  private String text = null;

  // ---------------------------------------------------------------------------

  /**
   * Constructs a text action.
   * 
   * @param text_
   *          The text to display.
   * @param location
   *          The baseline of the first character.
   * @author Hans Marquard
   */
  public Text(String text_, Point location)
  {
    super(TYPE.TEXT);
    super.setStart(location);
    text = new String(text_);
    font = new Font("Dialog", Font.PLAIN, size);
  }

  // ---------------------------------------------------------------------------

  /**
   * Sets the font size.
   * 
   * @param size_ The size.
   * @author Hans Marquard
   * @author Matt Muccioli
   */
  public void setFontSize(int size_)
  {
    size = (int) 4*size_;
  }

  // ---------------------------------------------------------------------------

  /**
   * Sets the font directly.
   * 
   * @param font_ The font.
   * @author Han Solo
   */
  public void setFont(Font font_)
  {
    font = font_;
    // TODO: Update members: size, style.
  }
  
  // ---------------------------------------------------------------------------

  /**
   * Sets the font by its common name.
   * 
   * @param font_name The font name.
   * @author Han Solo
   */
  public void setFontByName(String font_name)
  {
    font = new Font(font_name, style, size);
  }

  // ---------------------------------------------------------------------------

  /**
   * Gets the text.
   * 
   * @return The text used when drawing.
   * @author Vidal Borromeo
   */
  public String getText()
  {
	  if(text == null) return new String("");
	  return text;
  }

  // ---------------------------------------------------------------------------
  
  /**
   * Sets the text.
   * 
   * @param text_
   *          The text to display.
   * @author Hans Marquard
   */
  public void setText(String text_)
  {
    if(text_ != null)
    {
      text = new String(text_);
    }
  }

  // ---------------------------------------------------------------------------

  /**
   * Implementation of abstract draw method. Draws this type of object.
   * 
   * @param g2
   *          The Graphics object to draw on.
   * @author [Implementor Goes Here]
   * @author Hans Marquard
   */
  public void draw(Graphics2D g2)
  {
    
    // the draw function in the graphics instance g
    Graphics2D g2D = (Graphics2D) g2; // cast to 2D
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
    g2D.setFont(font);
    g2D.setColor(color);

    g2D.drawString(text, start_pt.x, start_pt.y);
  }// draw

}// Text
